package com.sitanyun.merchant.guide.view.activity;

import android.app.Dialog;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.kanfang123.viewersdk.VRViewerManager;
import com.sitanyun.merchant.guide.R;
import com.sitanyun.merchant.guide.adapter.DialogActivityListAdatper;
import com.sitanyun.merchant.guide.bean.MessagesBean;
import com.sitanyun.merchant.guide.bean.UserVrBean;
import com.sitanyun.merchant.guide.weiht.CheckAudioPermission;
import com.sitanyun.merchant.guide.weiht.PermissionUtil;
import com.sitanyun.merchant.guide.weiht.SPutils;
import com.sitanyun.merchant.guide.weiht.SharedPreferenceUtil;
import com.tencent.imsdk.v2.V2TIMManager;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.imsdk.v2.V2TIMSendCallback;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

import androidx.fragment.app.FragmentActivity;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 接听弹窗
 */
public class DialogActivity extends FragmentActivity {

    @BindView(R.id.backgroud)
    ImageView backgroud;
    @BindView(R.id.cname)
    TextView cname;
    @BindView(R.id.tv_refuse)
    TextView tvRefuse;
    @BindView(R.id.tv_accept)
    TextView tvAccept;
    @BindView(R.id.cimgs)
    CircleImageView cimg;
    @BindView(R.id.llone)
    LinearLayout llone;
    @BindView(R.id.listUser)
    ListView listUser;
    @BindView(R.id.tv_refusetwo)
    TextView tvRefusetwo;
    @BindView(R.id.tv_acceptwo)
    TextView tvAcceptwo;
    @BindView(R.id.lltwo)
    LinearLayout lltwo;

    private MessagesBean messagesBean;
    private UserVrBean.CloudCustomDataBean cloudCustomDataBean;
    private ArrayList<MessagesBean>  messagesBeans  = new ArrayList<>(); ;
    private MediaPlayer mMediaPlayer;
    private DialogActivityListAdatper dialogActivityListAdatper;
    private String urlss;
    private String names;
    private String scenid;
    private String storeid;
    private String shops;
    private String starfname;
    private String headurl;
    private String headname;
    private String cid;
    private String cnames;
    private String cphone;
    private long aLong;
    private long time;
    public static DialogActivity test_a = null;
    private  String types;
    private String merchantNodeId;



    /**
     * @param savedInstanceState
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.meiting_item);
        ButterKnife.bind(this);
        //通知全局this
        test_a= this ;
        //点击外界不关闭
        setFinishOnTouchOutside(false);
        //先清除集合
        messagesBeans.clear();
     //   moveTaskToBack(true);

    }
    //接收第二条以及多条新消息
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);

    }
  //显示
    @Override
    protected void onResume() {
        super.onResume();
        //接收信息
        messagesBean = (MessagesBean) getIntent().getSerializableExtra("beans");
        //赋值
        Glide.with(DialogActivity.this).load(messagesBean.getHeadUrl()).into(cimg);
        cname.setText(messagesBean.getCName());
        //权限
        if (CheckAudioPermission.isVoicePermission()){
            //ToastUtil.showToast(DialogActivity.this,"有权限");
        }else {
            permissiondialog(0);

            return;
        }
        /** 倒计时60秒，一次1秒 */
        CountDownTimer timer = new CountDownTimer(60 * 1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                // TODO Auto-generated method stub
                //  textView_time_shengxu.setText("还剩"+millisUntilFinished/1000+"秒");
                time = millisUntilFinished/1000;
                Log.e("times",time+"");
            }
          //倒计时结束
            @Override
            public void onFinish() {
                for (int i = 0; i <messagesBeans.size() ; i++) {
                    if (messagesBeans.size()==1){
                        finish();
                        messagesBeans.clear();
                    }else if (messagesBeans.size()>1){

                        SimpleDateFormat fmtrq = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
                        Date now = new Date();
                        String value=messagesBeans.get(i).getStartTime();
                        Date robottime = null;
                        try {
                            robottime = fmtrq.parse(value);
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        messagesBeans.remove(0);
                        dialogActivityListAdatper.setPosition(0);
                        dialogActivityListAdatper.notifyDataSetChanged();
//                        if(now.getTime()-robottime.getTime()>=600000){//1000表示1秒
//                            System.out.println("超过60秒");
//                            Log.e("times","超过60秒");
//                            messagesBeans.remove(i);
//                            dialogActivityListAdatper.setPosition(0);
//                            dialogActivityListAdatper.notifyDataSetChanged();
//                        }else {
//                            Log.e("times","没有超过60秒");
//
//                        }
                        //   messagesBeans.remove(0);
                        // dialogActivityListAdatper.notifyDataSetChanged();
                    }else {
                        finish();
                        messagesBeans.clear();
                    }
                }

            }
        }.start();
        //铃声
        try {
            mMediaPlayer = new MediaPlayer();
            AssetFileDescriptor fd = getAssets().openFd("kanong.mp3");
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                mMediaPlayer.setDataSource(fd);
                mMediaPlayer.prepare();
                mMediaPlayer.start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        //创建集合保存获取数据
        MessagesBean messagesBeanss = new MessagesBean(messagesBean.getBehavior()
                , messagesBean.getMerchantNodeId(), messagesBean.getSceneId()
                , messagesBean.getSceneName(), messagesBean.getStoreId(), messagesBean.getStoreName()
                , messagesBean.getStaffId(), messagesBean.getStaffName(), messagesBean.getCId()
                , messagesBean.getShareCId(), messagesBean.getVrsrc(), messagesBean.getHeadUrl()
                , messagesBean.getCName(), messagesBean.getCPhone(), messagesBean.getHeartTime()
                , messagesBean.getStartTime(), messagesBean.getEndTime());
       //获取数据添加到集合
        messagesBeans.add(messagesBeanss);
          //循环过滤数据，  到后台状态以及其他。
        for(int i = 0;i<messagesBeans.size();i++){//循环list
            for(int j = i+1;j<messagesBeans.size();j++){
         //   for (int j = messagesBeans.size() - 1; j > i; j--) {
                if(messagesBeans.get(i).equals(messagesBeans.get(j))){
                    messagesBeans.remove(i);//删除一样的元素
                    i--;
                    break;
                }
            }
        }

        //集合大于1为多人
        if (messagesBeans.size() > 1) {
            //默认选择第一个
            urlss =     messagesBeans.get(0).getVrsrc();
            names =     messagesBeans.get(0).getSceneName();
            scenid =     messagesBeans.get(0).getSceneId();
            storeid =     messagesBeans.get(0).getStoreId();
            shops =     messagesBeans.get(0).getStoreName();
            starfname =     messagesBeans.get(0).getStaffName();
            headurl =     messagesBeans.get(0).getHeadUrl();
            headname =     messagesBeans.get(0).getCName();
            cid = messagesBeans.get(0).getCId();
            cnames = messagesBeans.get(0).getCName();
            cphone = messagesBeans.get(0).getCPhone();

            if (SPutils.getStringData("meetingstar").equals("meeting_start")) {
                tvRefusetwo.setText("保持当前");
                tvAcceptwo.setText("挂断当前并接通");
            } else {
                tvRefusetwo.setText("拒绝");
                tvAcceptwo.setText("接受");

            }
            //设置窗口
            getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            getWindow().setGravity(Gravity.CENTER);
            //隐藏显示
            llone.setVisibility(View.GONE);
            lltwo.setVisibility(View.VISIBLE);
            //适配器
            dialogActivityListAdatper = new DialogActivityListAdatper(messagesBeans,DialogActivity.this);
            listUser.setAdapter(dialogActivityListAdatper);

        } else {
            //单人
            getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            if (SPutils.getStringData("meetingstar").equals("meeting_start")) {
                tvRefuse.setText("保持当前");
                tvAccept.setText("挂断当前并接通");
            } else {
                tvRefuse.setText("拒绝");
                tvAccept.setText("接受");
            }
            //弹窗样式
            getWindow().setGravity(Gravity.BOTTOM);
            llone.setVisibility(View.VISIBLE);
            lltwo.setVisibility(View.GONE);

        }
        //多用户点击选择事件
        listUser.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                dialogActivityListAdatper.setPosition(position);
                dialogActivityListAdatper.notifyDataSetChanged();
                urlss =     messagesBeans.get(position).getVrsrc();
                names =     messagesBeans.get(position).getSceneName();
                scenid =     messagesBeans.get(position).getSceneId();
                merchantNodeId = messagesBeans.get(position).getMerchantNodeId();
                storeid =     messagesBeans.get(position).getStoreId();
                shops =     messagesBeans.get(position).getStoreName();
                starfname =     messagesBeans.get(position).getStaffName();
                headurl =     messagesBeans.get(position).getHeadUrl();
                headname =     messagesBeans.get(position).getCName();
                cid = messagesBeans.get(position).getCId();
                cnames = messagesBeans.get(position).getCName();
                cphone = messagesBeans.get(position).getCPhone();

            }
        });
    }


    /**
     * 接听方式
     * @param view
     */
    @OnClick({R.id.tv_refuse, R.id.tv_accept, R.id.tv_refusetwo, R.id.tv_acceptwo
    })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            //取消
            case R.id.tv_refuse:

                try {
                    if (mMediaPlayer.isPlaying()){
                        mMediaPlayer.stop();
                    }
                }catch (Exception e){

                }
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// HH:mm:ss
                Date date = new Date(System.currentTimeMillis());
                cloudCustomDataBean = new UserVrBean.CloudCustomDataBean(
                        "MEETING_REJECT",
                        SharedPreferenceUtil.getStringData("tonodeid")
                        , messagesBean.getSceneId()
                        , messagesBean.getSceneName()
                        , messagesBean.getStoreId()
                        , messagesBean.getStoreName()
                        , SharedPreferenceUtil.getStringData("staffid")
                        , SharedPreferenceUtil.getStringData("staffname")
                        , messagesBean.getCId(),
                        messagesBean.getCName(),
                        messagesBean.getCPhone(),
                        "0", simpleDateFormat.format(date));
                V2TIMMessage v2TIMMessage = V2TIMManager.getMessageManager().createCustomMessage(messagesBean.getCName().getBytes());
                // 发送消息
                String msgs = JSON.toJSONString(cloudCustomDataBean);
                v2TIMMessage.setCloudCustomData(msgs);
                V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, "cid_" + messagesBean.getCId(), null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, null, new V2TIMSendCallback<V2TIMMessage>() {
                    @Override
                    public void onError(int code, String desc) {
                        Log.e("TAG", code + "" + desc);
                    }

                    @Override
                    public void onSuccess(V2TIMMessage v2TIMMessage) {
                        Log.e("TAG", "onSuccess");
                    }

                    @Override
                    public void onProgress(int progress) {
                        Log.e("TAG", "progress");
                    }
                });
                messagesBeans.clear();
                finish();

                break;
                //接通
            case R.id.tv_accept:
                //保存数据
                SPutils.SaveData("meetingstar", "meeting_start");
                SPutils.SaveData("meetingstars", messagesBean.getCId());
                try {
                    if (mMediaPlayer.isPlaying()){
                        mMediaPlayer.stop();
                    }
                }catch (Exception e){

                }

                SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// HH:mm:ss
                Date date1 = new Date(System.currentTimeMillis());

                cloudCustomDataBean = new UserVrBean.CloudCustomDataBean(
                        "MEETING_START",
                        SharedPreferenceUtil.getStringData("tonodeid")
                        , messagesBean.getSceneId()
                        , messagesBean.getSceneName()
                        , messagesBean.getStoreId()
                        , messagesBean.getStoreName()
                        , SharedPreferenceUtil.getStringData("staffid")
                        , SharedPreferenceUtil.getStringData("staffname")
                        , messagesBean.getCId(),
                        messagesBean.getCName(),
                        messagesBean.getCPhone(),
                        "0", simpleDateFormat1.format(date1));

                V2TIMMessage v2TIMMessages = V2TIMManager.getMessageManager().createCustomMessage(messagesBean.getCName().getBytes());
                // 发送消息
                String msg = JSON.toJSONString(cloudCustomDataBean);
                v2TIMMessages.setCloudCustomData(msg);
                V2TIMManager.getMessageManager().sendMessage(v2TIMMessages, "cid_" + messagesBean.getCId(), null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, null, new V2TIMSendCallback<V2TIMMessage>() {
                    @Override
                    public void onError(int code, String desc) {
                        Log.e("TAG", code + "" + desc);
                    }

                    @Override
                    public void onSuccess(V2TIMMessage v2TIMMessage) {
                        Log.e("TAG", "onSuccess");
                    }

                    @Override
                    public void onProgress(int progress) {
                        Log.e("TAG", "progress");
                    }
                });
                    //判断是否接通
                if (tvAccept.getText().toString().trim().equals("挂断当前并接通")) {
                    SPutils.SaveData("exim", "exims");
                    VRViewerManager.INSTANCE.appEndTour$viewersdk_release();
                types="4";
                }else {
               types="1";
            }
                //跳转
                startActivity(new Intent(DialogActivity.this, VrWebActivity.class)
                        .putExtra("urlss", messagesBean.getVrsrc())
                        .putExtra("names", messagesBean.getSceneName())
                        .putExtra("scenid", messagesBean.getSceneId())
                        .putExtra("storeid", messagesBean.getStoreId())
                        .putExtra("shops", messagesBean.getStoreName())
                        .putExtra("starfname", messagesBean.getStaffName())
                        .putExtra("headurl", messagesBean.getHeadUrl())
                        .putExtra("headname", messagesBean.getCName())
                        .putExtra("cphone",messagesBean.getCPhone()+"")
                        .putExtra("cids", messagesBean.getCId()+"")
                        .putExtra("type", types));
                messagesBeans.clear();
                finish();

                break;
            //多人dialog样式取消
            case R.id.tv_refusetwo:
               //关闭铃声
                try {
                    if (mMediaPlayer.isPlaying()){
                        mMediaPlayer.stop();
                    }
                }catch (Exception e){

                }
                for (int i = 0; i <messagesBeans.size() ; i++) {
                  SimpleDateFormat simpleDateFormats = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// HH:mm:ss
                        Date dates = new Date(System.currentTimeMillis());
               cloudCustomDataBean  = new UserVrBean.CloudCustomDataBean(
                                "MEETING_REJECT",
                       SharedPreferenceUtil.getStringData("tonodeid")
                                ,  messagesBeans.get(i).getSceneId()
                                ,  messagesBeans.get(i).getSceneName()
                                ,  messagesBeans.get(i).getStoreId()
                                ,  messagesBeans.get(i).getStoreName()
                                , SharedPreferenceUtil.getStringData("staffid")
                                , SharedPreferenceUtil.getStringData("staffname")
                                ,  messagesBeans.get(i).getCId(),
                                messagesBeans.get(i).getCName(),
                                messagesBeans.get(i).getCPhone(),
                                "0", simpleDateFormats.format(dates));

                        V2TIMMessage v2TIMMess = V2TIMManager.getMessageManager().createCustomMessage("1".getBytes());
                        // 发送消息
                        String msgss = JSON.toJSONString(cloudCustomDataBean);
                        v2TIMMess.setCloudCustomData(msgss);
                        V2TIMManager.getMessageManager().sendMessage(v2TIMMess, "cid_" + messagesBeans.get(i).getCId(), null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, null, new V2TIMSendCallback<V2TIMMessage>() {
                            @Override

                            public void onError(int code, String desc) {
                                Log.e("TAG", code + "" + desc);
                            }

                            @Override
                            public void onSuccess(V2TIMMessage v2TIMMessage) {
                                Log.e("TAG", "onSuccess");
                            }

                            @Override
                            public void onProgress(int progress) {
                                Log.e("TAG", "progress");
                            }
                        });
                   }
                messagesBeans.clear();
                finish();
                break;
                //第二种接通
            case R.id.tv_acceptwo:
                SPutils.SaveData("meetingstar", "meeting_start");
                SPutils.SaveData("meetingstars", cid);
                //默认第一条
                try {
                    if (mMediaPlayer.isPlaying()){
                        mMediaPlayer.stop();
                    }
                }catch (Exception e){

                }
                //发送消息
                SimpleDateFormat simpleDateFormatss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// HH:mm:ss
                Date datess = new Date(System.currentTimeMillis());
                //循环判断接哪个用户
                for (int i = 0; i <messagesBeans.size() ; i++) {
                    if (cid.equals(messagesBeans.get(i).getCId())){
                        cloudCustomDataBean = new UserVrBean.CloudCustomDataBean(
                                "MEETING_START",
                                SharedPreferenceUtil.getStringData("tonodeid")
                                ,scenid
                                , names
                                ,storeid
                                , shops
                                , SharedPreferenceUtil.getStringData("staffid")
                                , SharedPreferenceUtil.getStringData("staffname")
                                , cid,
                                cnames,
                                cphone,
                                "0", simpleDateFormatss.format(datess));

                        V2TIMMessage v2TIMMessagess = V2TIMManager.getMessageManager().createCustomMessage(messagesBean.getCName().getBytes());
                        // 发送消息
                        String msg3 = JSON.toJSONString(cloudCustomDataBean);
                        v2TIMMessagess.setCloudCustomData(msg3);
                        V2TIMManager.getMessageManager().sendMessage(v2TIMMessagess, "cid_" +cid, null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, null, new V2TIMSendCallback<V2TIMMessage>() {
                            @Override
                            public void onError(int code, String desc) {
                                Log.e("TAG", code + "" + desc);
                            }

                            @Override
                            public void onSuccess(V2TIMMessage v2TIMMessage) {
                                Log.e("TAGS", "cg");
                            }

                            @Override
                            public void onProgress(int progress) {
                                Log.e("TAG", "progress");
                            }
                        });

                    }else {
                        //拒绝其他用户发送消息
                        SimpleDateFormat simpleDateFormat0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// HH:mm:ss
                        Date date0 = new Date(System.currentTimeMillis());
                        cloudCustomDataBean = new UserVrBean.CloudCustomDataBean(
                                "MEETING_REJECT",
                                SharedPreferenceUtil.getStringData("tonodeid")
                                , messagesBeans.get(i).getSceneId()
                                , messagesBeans.get(i).getSceneName()
                                , messagesBeans.get(i).getStoreId()
                                , messagesBeans.get(i).getStoreName()
                                , SharedPreferenceUtil.getStringData("staffid")
                                , SharedPreferenceUtil.getStringData("staffname")
                                , messagesBeans.get(i).getCId(),
                                messagesBeans.get(i).getCName(),
                                messagesBeans.get(i).getCPhone(),
                                "0", simpleDateFormat0.format(date0));

                        V2TIMMessage v2TIMMessagess = V2TIMManager.getMessageManager().createCustomMessage(messagesBean.getCName().getBytes());
                        // 发送消息
                        String msg3 = JSON.toJSONString(cloudCustomDataBean);
                        v2TIMMessagess.setCloudCustomData(msg3);
                        V2TIMManager.getMessageManager().sendMessage(v2TIMMessagess, "cid_" + messagesBeans.get(i).getCId(), null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, null, new V2TIMSendCallback<V2TIMMessage>() {
                            @Override
                            public void onError(int code, String desc) {
                                Log.e("TAG", code + "" + desc);
                            }

                            @Override
                            public void onSuccess(V2TIMMessage v2TIMMessage) {
                                Log.e("TAGS", "拒绝其他");
                            }

                            @Override
                            public void onProgress(int progress) {
                                Log.e("TAG", "progress");
                            }
                        });
                    }
                }

                //判断当前状态
                if (tvAcceptwo.getText().toString().trim().equals("挂断当前并接通")) {
                    SPutils.SaveData("exim", "exims");
                    VRViewerManager.INSTANCE.appEndTour$viewersdk_release();
                    types="4";
                }else {
                    types="1";
                }  //跳转

                startActivity(new Intent(DialogActivity.this, VrWebActivity.class)
                        .putExtra("urlss",urlss)
                        .putExtra("names", names)
                        .putExtra("scenid", scenid)
                        .putExtra("storeid", storeid)
                        .putExtra("shops", shops)
                        .putExtra("starfname",starfname)
                        .putExtra("headurl", headurl)
                        .putExtra("headname", headname)
                        .putExtra("type", types)
                         .putExtra("cphone",cphone)
                         .putExtra("cids", cid));
                messagesBeans.clear();
                finish();
                break;
        }
    }

   //权限弹窗
    private void permissiondialog(int i) {
        //1、使用Dialog、设置style
        final Dialog dialog = new Dialog(DialogActivity.this, R.style.DialogTheme);
        //2、设置布局
        View view = View.inflate(DialogActivity.this, R.layout.permisen_dialog, null);
        dialog.setContentView(view);
        CheckBox cbpms=(CheckBox) view.findViewById(R.id.cb_pms);
        LinearLayout llpms=(LinearLayout) view.findViewById(R.id.ll_pms);

        if (i==0){
            llpms.setVisibility(View.GONE);
        }else {
            llpms.setVisibility(View.VISIBLE);
        } //权限点击事件
        view.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                finish();
                if (cbpms.isChecked()){
                    messagesBeans.clear();
                    SharedPreferenceUtil.SaveData("pms","0");
                }else {
                    SharedPreferenceUtil.SaveData("pms","1");
                }
            }
        });
        view.findViewById(R.id.tv_setup).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                messagesBeans.clear();
                if (cbpms.isChecked()){
                    SharedPreferenceUtil.SaveData("pms","0");
                }else {
                    SharedPreferenceUtil.SaveData("pms","1");
                }
                PermissionUtil.gotoPermission(DialogActivity.this);
            }
        });


        Window window = dialog.getWindow();
        //设置弹出位置
        window.setGravity(Gravity.CENTER);
        //  window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        //设置弹出动画
        //   window.setWindowAnimations(R.style.main_menu_animStyle);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        dialog.setCancelable(false);
        dialog.show();
        /*添加View到当前显示的Activity*/
        //   MerchantApp.getInstance().showView(view);

    }
   //隐藏
    @Override
    protected void onPause() {
        super.onPause();
        if (mMediaPlayer != null) {
            mMediaPlayer.release();
        }

    }
    //结束
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mMediaPlayer != null) {
            mMediaPlayer.release();
        }
    }



}
